//package com.cdxy.message.consumer;
//
//import com.cdxy.enums.mq.RabbitQueueNameEnum;
//import com.cdxy.model.dto.base.exception.BusinessException;
//import com.cdxy.service.IMqInnerService;
//import com.rabbitmq.client.Channel;
//import com.rabbitmq.client.impl.AMQImpl;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
///**
// * @Author: tangy
// * @Date: 2020/6/10 10:06
// */
//@Slf4j
//@Component
//public class BusinessConsumer {
//
//    @Autowired
//    private IMqInnerService mqInnerService;
//
//    @RabbitListener(queues = RabbitQueueNameEnum.BUSINESS_QUEUE_A)
//    @RabbitHandler
//    public void businessQueueA(Message message, Channel channel) {
//        String a = new String(message.getBody());
//        log.info("业务消息队列A。收到消息：{}", a);
//        boolean ack = true;
//        Exception exception = null;
//        try {
//            if (a.equals("exception")) {
//                throw new BusinessException("deadLetter");
//            }
//        } catch (Exception e) {
//            ack = false;
//            exception = e;
//        }
//        try {
//            if (!ack) {
//                log.info("消息队列发生异常");
//                channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//            } else {
//                channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//            }
//        } catch (Exception e) {
//            log.info("消息队列回调失败");
//        }
//    }
//
//    @RabbitListener(queues = RabbitQueueNameEnum.BUSINESS_QUEUE_B)
//    @RabbitHandler
//    public void businessQueueB(Message message, Channel channel) {
//        String a = new String(message.getBody());
//        log.info("消息队列B 收到消息：{}", a);
//        try {
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            log.error("业务队列B，回调异常", e);
//        }
//    }
//
//}
